//
//  WBBaseRequest.h
//  WeatherBar
//
//  Created by Bert on 2024/6/7.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger,RequestStatus) {
    /// 请求成功
    RequestStatusSuccess = 1,
    /// 无网络
    RequestStatusCanNotReachable,
    /// 请求失败
    RequestStatusRemoteFaild,
    /// 格式错误
    RequestStatusFormatError,
    /// 定位失败
    RequestStatusLocationError,
};

typedef NS_ENUM(NSUInteger,RequestType) {
    /// POST
    RequestTypePost = 1,
    /// GET
    RequestTypeGet,
    /// PUT
    RequestTypePut,
    /// DELETE
    RequestTypeDelete,
};

@class WBBaseRequest;

typedef void(^RequestResultsBlock)(RequestStatus status,id _Nullable responseObject);

typedef void(^successBlock)(WBBaseRequest *operation,BOOL isSuccess, id responseObject);

typedef void(^failureBlock)(WBBaseRequest *operation, NSError *error);


@interface WBBaseRequest : NSObject
/// 要拼接的接口短链
@property(nonatomic, strong) NSString *methodName;
/// 请求参数
@property(nonatomic, strong) NSMutableDictionary *bodyDic;
@property(nonatomic, strong) NSMutableDictionary *headerDic;
@property (nonatomic ,strong) NSData *data;
@property (nonatomic ,copy) NSArray <NSData *> *imageArray;
/// 提示信息
@property(nonatomic, strong) NSString *resultMessage;
/// 返回码
@property(nonatomic, strong) NSString *code;
/// 是否是 200?YES:NO
@property(nonatomic) BOOL isError;
/// 利用网络状态区分错误提示
@property(nonatomic) RequestStatus requestStatus;
/// 请求方式
@property (nonatomic ,assign) RequestType requestType;



 //--------------------------------类方法--------------------------------------
 
 #pragma mark 类方法
 /**
 包含BaseUrl的请求
 
 @param methodName 方法名字
 @param parametersDic 参数
 @param success 成功回调
 */
+ (void)postRequestWithMethodName:(NSString *)methodName
parametersDic:(NSDictionary *)parametersDic
success:(successBlock)success;

/**
 get包含Baseurl的请求
 
 @param methodName 方法名字
 @param parametersDic 参数
 @param success 成功回调
 */
+(void)getRequestWithMethodName:(NSString *)methodName
parametersDic:(NSDictionary *)parametersDic
success:(successBlock)success;

/**
 put包含Baseurl的请求
 
 @param methodName 方法名字
 @param parametersDic 参数
 @param success 成功回调
 */
+(void)putRequestWithMethodName:(NSString *)methodName
parametersDic:(NSDictionary *)parametersDic
success:(successBlock)success;

/**
 delete包含Baseurl的请求
 
 @param methodName 方法名字
 @param parametersDic 参数
 @param success 成功回调
 */
+(void)deleteRequestWithMethodName:(NSString *)methodName
parametersDic:(NSDictionary *)parametersDic
success:(successBlock)success;


/**
 上传头像的请求
 
 @param methodName 方法名字
 @param data 二进制
 @param success 成功回调
 */
+(void)postImageWithMethodName:(NSString *)methodName
                                 data:(NSData *)data
                              success:(successBlock)success;

/**
 上传多张头像的请求
 
 @param methodName 方法名字
 @param images 二进制数组
 @param success 成功回调
 */
+(void)postImagesArrayWithMethodName:(NSString *)methodName
                                      data:(NSArray <NSData *>*)images
                                   success:(successBlock)success;

+(WBBaseRequest*)initRequestWithMethodName:(NSString *)methodName
                             parametersDic:(NSDictionary *)parametersDic;



//--------------------------------对象方法--------------------------------------

//发送 POST 请求
/**
 @param success 成功回调
 @param failure 失败回调
 */
- (void)postRequestSuccess:(void (^)(WBBaseRequest *operation, id responseObject))success
failure:(void (^)(WBBaseRequest *operation, NSError *error))failure;

/**
 可以修改 BaseUrl 的 POST 请求
 
 @param url 完整的url
 @param success 成功回调
 @param failure 失败回调
 */
- (void)postWithFullUrl:(NSString *)url
success:(void (^)(WBBaseRequest *operation, id responseObject))success
failure:(void (^)(WBBaseRequest *operation, NSError *error))failure;

/**
 GET 请求
 
 @param success 成功回调
 @param failure 失败回调
 */
- (void)getRequestSuccess:(void (^)(WBBaseRequest *operation, id responseObject))success
failure:(void (^)(WBBaseRequest *operation, NSError *error))failure;

/**
 PUT 请求
 
 @param success 成功回调
 @param failure 失败回调
 */
- (void)putRequestSuccess:(void (^)(WBBaseRequest *operation, id responseObject))success
failure:(void (^)(WBBaseRequest *operation, NSError *error))failure;


/**
 DELETE 请求
 
 @param success 成功回调
 @param failure 失败回调
 */
- (void)deleteRequestSuccess:(void (^)(WBBaseRequest *operation, id responseObject))success
failure:(void (^)(WBBaseRequest *operation, NSError *error))failure;


/**
 上传头像
 
 @param image 图片数据
 @param success 成功回调
 @param failure 失败回调
 */
- (void)postImageWithImage:(UIImage *)image
success:(void (^)(WBBaseRequest *operation, id responseObject))success
failure:(void (^)(WBBaseRequest *operation, NSError *error))failure;

/**
 上传多张图片
 
 @param images 图片数据的数组
 @param success 成功回调
 @param failure 失败回调
 */
- (void)postImageWithImagesData:(NSArray <UIImage *>*)images
success:(void (^)(WBBaseRequest *operation, id responseObject))success
failure:(void (^)(WBBaseRequest *operation, NSError *error))failure;


- (void)startRequestWithType:(RequestType)type
                     success:(void (^)(WBBaseRequest *operation, id responseObject))success
                     failure:(void (^)(WBBaseRequest *operation, NSError *error))failure;


//----------------------------------------------------------------------



///多种方式设置参数
- (void)setIntegerValue:(NSInteger)value forKey:(NSString *)key;
- (void)setDoubleValue:(double)value forKey:(NSString *)key;
- (void)setLongLongValue:(long long)value forKey:(NSString *)key;
- (void)setBOOLValue:(BOOL)value forKey:(NSString *)key;
- (void)setValue:(id __nullable)value forKey:(NSString *)key;

@end

NS_ASSUME_NONNULL_END
